﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using _3Dsoundor2Dgraphor.Graphics;
using _3Dsoundor2Dgraphor.Sound;


namespace _3Dsoundor2Dgraphor
{
	public partial class _3Dsoundor2Dgraphor : Form
	{

		private const int GRAPHICWINDOW_X = 409;
		private const int GRAPHICWINDOW_Y = 12;
		private const int GRAPHICWINDOW_WIDTH = 763;
		private const int GRAPHICWINDOW_HEIGHT = 658;

		private int speed = 3;
		private SolidBrush mBrushBlack, mBrushGrey;

		private Root root;


		public _3Dsoundor2Dgraphor()
		{
			InitializeComponent();
			windowStarup();
			main();

		}
		private void OnPaint(object sender, PaintEventArgs e)
		{
			e.Graphics.FillRectangle(mBrushBlack, GRAPHICWINDOW_X, GRAPHICWINDOW_Y, GRAPHICWINDOW_WIDTH, GRAPHICWINDOW_HEIGHT);
			root.refresh(e.Graphics);

		}

		public void windowStarup()
		{
			SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
			mBrushBlack = new SolidBrush(Color.Black);
			mBrushGrey = new SolidBrush(Color.Green);

			label2.Text = speed.ToString();
			trackBar1.Value = speed;

			label4.Text = SoundBase.DISTANCEFACTOR.ToString();
			trackBar2.Value = (int)SoundBase.DISTANCEFACTOR;






			root = new Root(GRAPHICWINDOW_X, GRAPHICWINDOW_Y, GRAPHICWINDOW_WIDTH, GRAPHICWINDOW_HEIGHT);

			Graphics.Object pierwszy = new Graphics.Object(10,20,Color.DeepPink,20);
			Graphics.Object drugi = new Graphics.Object(100, 100, Color.DeepSkyBlue, 20, true, 200, 200, 2, 140);
			drugi.moveable = true;

			pierwszy.createSound("c:\\sounds\\drumloop.wav", false);
			drugi.createSound("c:\\sounds\\drumloop.wav", false);
			root.addObject(pierwszy);
			root.addObject(drugi);

		}

		public void main()
		{
			Invalidate();
		}



		private void _3Dsoundor2Dgraphor_KeyDown(object sender, KeyEventArgs e)
		{
			switch (e.KeyCode)
			{
				case Keys.W: root.movePlayer(0, -speed); break;
				case Keys.S: root.movePlayer(0, speed); break;
				case Keys.A: root.movePlayer(-speed, 0); break;
				case Keys.D: root.movePlayer(speed, 0); break;
				case Keys.E: root.action(); break;
				case Keys.Q: root.stopAction(PointF.Empty); break;
			}
			Invalidate();
		}

		private void trackBar1_Scroll(object sender, EventArgs e)
		{
			speed = trackBar1.Value;
			label2.Text = speed.ToString();
		}

		private void timer1_Tick(object sender, EventArgs e)
		{
			Invalidate();
			Element.time += 1;
		}

		private void trackBar2_Scroll(object sender, EventArgs e)
		{
			SoundBase.DISTANCEFACTOR = trackBar2.Value/100.0f;
			label4.Text = (SoundBase.DISTANCEFACTOR*100).ToString();
		}


	}
}
